#!/bin/bash

function downLoadGolang() {
    wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz
    tar xf go1.20.2.linux-amd64.tar.gz -C /usr/local
}

function addEnv() {
    echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile.d/golang.sh
    source /etc/profile
}

function changeGoPorxy() {
    go env -w GO111MODULE=on
    go env -w GOPROXY=https://goproxy.cn,direct
}

function main() {
    go env
    if [[ $? != 0 ]]; then
        downLoadGolang
        addEnv
        changeGoPorxy
    else
        echo "You already installed go!!"
    fi

}

main
